/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package poli.reserva.dao;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
import poli.reserva.base.reservaSilla;
import poli.reserva.base.silla;
import poli.reserva.base.vuelo;

/**
 *
 * @author Pc
 */
public class JSillaMySQL {
    
    
     public List<silla> selectJReservaSillaMySQL(){
        
        Connection conn = null;
        Statement st = null;
        ResultSet rs = null;
        conexion conect = new conexion();
         conn=  conect.conexionMySQL();
        ArrayList resultado = new ArrayList();
        
    
        try {
        
            
         String query = "SELECT * FROM silla ;";   
        
        st = conn.createStatement();   
        
         rs = st.executeQuery(query);   
           
            while (rs.next())
      {
           silla silla = new silla();
           silla.setId_silla(rs.getString(1));
           silla.setNumero_silla(rs.getString(2));
           silla.setLetra_silla(rs.getString(3));
           silla.setEstado_silla(rs.getBoolean(4));
           
          
           
           resultado.add(silla);
                }
            
            st.close();
           }
           
       
    catch (SQLException ex) {
           System.err.println(ex.getMessage());
        }
        return resultado;
        
    }
     
     public List<silla> selectJReservaSillaMySQLIDSilla(String id_silla){
        
        Connection conn = null;
        Statement st = null;
        ResultSet rs = null;
        conexion conect = new conexion();
         conn=  conect.conexionMySQL();
        ArrayList resultado = new ArrayList();
        
    
        try {
        
            
         String query = "SELECT * FROM silla where id_silla = '"+id_silla+"' ;";   
        
        st = conn.createStatement();   
        
         rs = st.executeQuery(query);   
           
            while (rs.next())
      {
           silla silla = new silla();
           silla.setId_silla(rs.getString(1));
           silla.setNumero_silla(rs.getString(2));
           silla.setLetra_silla(rs.getString(3));
           silla.setEstado_silla(rs.getBoolean(4));
           
          
           
           resultado.add(silla);
                }
            
            st.close();
           }
           
       
    catch (SQLException ex) {
           System.err.println(ex.getMessage());
        }
        return resultado;
        
    }
     
      public Boolean insertJVueloMySQL(silla JSilla){
        Connection conn = null;
        Statement st = null;
        ResultSet rs = null;
        conexion conect = new conexion();
         conn=  conect.conexionMySQL();
         
         boolean result = false;
          try {
        
            
         String query = "INSERT INTO vuelo (id_silla, numero_silla, letra_silla, estado_silla)"+
                 " VALUES ( '"+JSilla.getId_silla()+"' , '"+JSilla.getNumero_silla()+"' , '"+JSilla.getLetra_silla()+"' , '"+JSilla.getEstadoSilla()+"' );";   
        
        st = conn.createStatement();
        
        result =  st.execute(query);
        
            conn.close();     
            st.close();
           }
           
      
    catch (SQLException ex) {
           System.err.println(ex.getMessage());
        }
        
         if (result!= true){
             
             return result;
         }
         
         else
             
        return true;
        
    }
}
